extends Tile

var utils
var base
func _ready():
	if not sys.has_node("VEBase"):
		base = load(data.infoDs["VEBase"]["VEBase"].dir).new()
		base.name = "VEBase"
		sys.add_child(base)
	else:
		base = sys.get_node("VEBase")
	utils = base.utils
	rollBG()
	
	for i in data.getList("c"):
		i = data.newBase(i.id)
		if utils.getModNameFromData(i) == "原版" and i.lock != -1:
			if i.origin.find("谜团") > -1 or i.origin.find("祭坛") > -1:
				i.lock = 1
			else:
				i.lock = 0
				data.achUlock(i)
		
func rollBG():
	if base.bgPics.empty():
		return
	var pic = sys.rndListItem(base.bgPics)
	$TextureRect.texture = load(pic)
	
func _on_Button4_pressed():
	#用于兼容箱庭地图MOD
	var boxFlag = data.infoDs.has("worldMap1")
	var towerFlag = sys.has_node("veTower")
		
	if boxFlag and not towerFlag:
		var dlg = sys.newDlg("res://!ve/additional/selModeDlgLoading/boxMap/selModeDlg.tscn")
		# var dlg = sys.newDlg("res://!ve/additional/selModeDlg/tower/selModeDlg.tscn")
	elif not boxFlag and towerFlag:
		var dlg = sys.newDlg("res://!ve/additional/selModeDlgLoading/tower/selModeDlg.tscn")
	elif boxFlag and towerFlag:
		sys.newDlg("res://!ve/additional/selModeDlgLoading/both/selModeDlg.tscn")
	else:
		queue_free()
		var game = load("res://tscn/game/game.tscn").instance()
		game.mode = loadMode
		sys.main.add_child(game)
		game.loadGame()

func _on_Button_pressed():
#	if sys.isBeta:
	#用于兼容箱庭地图MOD
	var boxFlag = data.infoDs.has("worldMap1")
	var towerFlag = sys.has_node("veTower")
	if not checkChara():
		sys.newMsg("启用人数不够！")
		return
	
	if boxFlag and not towerFlag:
		var dlg = sys.newDlg("res://!ve/additional/selModeDlg/boxMap/selModeDlg.tscn")
		# var dlg = sys.newDlg("res://!ve/additional/selModeDlg/tower/selModeDlg.tscn")
	elif not boxFlag and towerFlag:
		var dlg = sys.newDlg("res://!ve/additional/selModeDlg/tower/selModeDlg.tscn")
	elif boxFlag and towerFlag:
		sys.newDlg("res://!ve/additional/selModeDlg/both/selModeDlg.tscn")
	else:
		var dlg = sys.newDlg("res://tscn/tile/selModeDlg.tscn")
#	else:

func checkChara():
#	var num1 = 0
#	var num2 = 0
#	for i in data.getList("c"):
#		var item = data.newBase(i.id)
#		if item.lock != -1:
#			if item.origin.find("城镇") > -1 and not data.disableDs.has(item.id):
#				num1 += 1
#			elif item.origin.find("地牢") > -1 and not data.disableDs.has(item.id):
#				num2 += 1
#	return num1 >= 12 and num2 >= 12
	return true
	
func _on_book_pressed():
	if sys.isDemo && sys.isTest == false:
		sys.newMsg("试玩版未解锁此功能")
		return
#	var dlg = sys.newDlg("res://tscn/book/bookDlg.tscn")
	var dlg = preload("res://tscn/book/bookDlg.tscn").instance()
	dlg.name = "bookDlg"
	sys.main.ui.add_child(dlg)
	dlg.popup()

